package lab03.test12;
import java.sql.*;
public class Test12 {
    public static void main(String[] args) {
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;
        String SQL1 = "select * from t_users";
        String SQL2 = "select * from t_users
        where username = 'admin'";
        String SQL3 = "select * from t_users
        where username = 'admin' and password = '123456'";
        String SQL4 = "select * from t_users
        where regsiter > 10000000";
        try {
            Class.forName(
                    "com.mysql.cj.jdbc.Driver");
            connection =
                    DriverManager.getConnection(
                            "jdbc:mysql://localhost:3306/java_2017?
                            serverTimezone=UTC&characterEncoding=utf-8","" + "root","123456");
                            statement =
                                    connection.createStatement();
            resultSet = statement.executeQuery(SQL1);
            while (resultSet.next()){
                System.out.print(resultSet.getInt(1) + "\t");
                System.out.print(resultSet.getString(2) + "\t");
                System.out.print(resultSet.getString(3) + "\t");
                System.out.print(resultSet.getLong(4));
                System.out.println();
            }
            resultSet = statement.executeQuery(SQL2);
            while (resultSet.next()){
                System.out.print(resultSet.getInt(1) + "\t");
                System.out.print(resultSet.getString(2) + "\t");
                System.out.print(resultSet.getString(3) + "\t");
                System.out.print(resultSet.getLong(4));
                System.out.println();
            }

            resultSet = statement.executeQuery(SQL3);
            while (resultSet.next()){
                System.out.print(resultSet.getInt(1) + "\t");
                System.out.print(resultSet.getString(2) + "\t");
                System.out.print(resultSet.getString(3) + "\t");
                System.out.print(resultSet.getLong(4));
                System.out.println()  }
            resultSet = statement.executeQuery(SQL4);
            while (resultSet.next()){
                System.out.print(resultSet.getInt(1) + "\t");
                System.out.print(resultSet.getString(2) + "\t");
                System.out.print(resultSet.getString(3) + "\t");
                System.out.print(resultSet.getLong(4));
                System.out.println();
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                statement.close();
                connection.close();
                resultSet.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

}
